﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
\* ######################################## */
using System;
using System.Diagnostics;
using System.Threading;
using System.Collections.Generic;
using System.Text;

using AJRavindiran.Jolt.RuneScape.Models.Characters;
using AJRavindiran.Jolt.RuneScape.Workers;
using AJRavindiran.Jolt.Utilities;

namespace AJRavindiran.Jolt.RuneScape
{
    /// <summary>
    /// Represents a game engine.
    /// </summary>
    public class GameEngine
    {
        #region Fields
        // Workers
        private LoginWorker loginWorker;
        private MajorUpdatesWorker majorUpdatesWorker;
        #endregion Fields

        #region Constructors
        /// <summary>
        /// Constructs a new game engine.
        /// </summary>
        public GameEngine()
        {
            Jolt.GetLog().WriteInfo("Constructing main game engine...");

            // --- WORKERS --- //
            // Build the login worker to process all logins.
            this.loginWorker = new LoginWorker();
            this.majorUpdatesWorker = new MajorUpdatesWorker();
        }
        #endregion Constructors

        #region Methods
        /// <summary>
        /// Starts all workers.
        /// </summary>
        public void Start()
        {
            Jolt.GetLog().WriteInfo("Starting all workers...");
            this.loginWorker.GetThread().Start();
            this.majorUpdatesWorker.GetThread().Start();
        }

        /// <summary>
        /// Aborts all workers.
        /// </summary>
        public void Abort()
        {
            Jolt.GetLog().WriteInfo("Aborting all workers...");
            this.loginWorker.GetThread().Abort();
            this.majorUpdatesWorker.GetThread().Abort();
        }

        /// <summary>
        /// Get accessor for the login worker.
        /// </summary>
        public LoginWorker GetLoginWorker()
        {
            return this.loginWorker;
        }

        /// <summary>
        /// Get accessor for the major updates worker.
        /// </summary>
        public MajorUpdatesWorker GetMajorWorker()
        {
            return this.majorUpdatesWorker;
        }
        #endregion Methods
    }
}
